package com.example.demo.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/session")
@RestController
public class SessionController {

    @RequestMapping("/getC2")
    public String getCookie2(@CookieValue("bite") String bite){
        return "从Cookie中获取特定的值，bite"+bite;
    }

    @RequestMapping("/setSession")
    public String setSession(HttpServletRequest request){
        HttpSession session = request.getSession();
        session.setAttribute("bite","张三");
        return "设置session成功";
    }
    
    @RequestMapping("getSesson01")
    public String getSession01(HttpServletRequest request){
        HttpSession session = request.getSession();
        String bite = (String)session.getAttribute("bite");
        return "从session中获取bite"+bite;
    }

    @RequestMapping("/getHeader")
    public String getHeader(HttpServletRequest request){
        String userAgent = request.getHeader("User-Agent");
        return "从Header中获取信息：User-Agent："+userAgent;
    }

    @RequestMapping("/getHeader2")
    public String getHeader2(@RequestHeader("User-Agent") String userAgent){
        return "从Header中获取User-Agent："+ userAgent;
    }


}
